<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">


          <a-col :xl="3" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="年级" prop="queryParam.gradeId">
              <!--              v-model="queryParam.gradeId"  对应java的Controller的接收参数vo对象的属性gradeId的值 -->
              <j-dict-select-tag @change='changeGradeId' v-model="queryParam.gradeId" placeholder="请选择年级" dictCode="cou_grade,grade_name,id,tenant_id  is not null order by  grade_order"/>
            </a-form-model-item>
          </a-col>

          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <!--                <a-input placeholder="请输入科目" v-model="queryParam.subjectId"></a-input>-->
            <a-form-model-item label="班级" prop="queryParam.classId">
              <!--                <j-select-multiple />   此处使用多选组件时，联动会失效，暂未解决联动失效问题-->
              <!--                <j-dict-select-tag />   单选正常联动，但无法多选查询-->

              <j-dict-select-tag v-model="queryParam.classId" placeholder="请选择班级" :dictCode="queryParamSelect.classIdSelect" />
            </a-form-model-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="考试" prop="queryParam.examinationId">
              <j-dict-select-tag @change='changeExaminationId' v-model="queryParam.examinationId"  placeholder="请选择考试" :dictCode="queryParamSelect.examinationIdSelect"/>
            </a-form-model-item>
          </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="评分标准" prop="queryParam.achiStandPurposeType">
              <!--                <j-dict-select-tag @change='changeAchievementStandardId' v-model="queryParam.achievementStandardId"  :dictCode="queryParamSelect.achievementStandardIdSelect"/>-->
              <j-multi-select-tag
                v-model="queryParam.achiStandPurposeType"
                dictCode="achi_stand_purpose_type"
                placeholder="请选择">
              </j-multi-select-tag>
            </a-form-model-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="计分范围(状态)" prop="queryParam.achievementStatus">
              <j-multi-select-tag
                v-model="queryParam.achievementStatus"
                dictCode="achievement_status"
                placeholder="请选择">
              </j-multi-select-tag>
            </a-form-model-item>
          </a-col>

        </a-row>

        <template v-if="toggleSearchStatus">
          <a-row :gutter="24">
            <a-col :xl="3" :lg="7" :md="8" :sm="24">
              <a-form-item label="学号">
                <a-input placeholder="请输入学生学号" v-model="queryParam.studentNo"></a-input>
              </a-form-item>
            </a-col>


            <a-col :xl="4" :lg="7" :md="8" :sm="24">
              <a-form-item label="学生姓名">
                <a-input placeholder="请输入学生姓名" v-model="queryParam.studentName"></a-input>
              </a-form-item>
            </a-col>


<!--            <a-col :xl="4" :lg="7" :md="8" :sm="24">-->
<!--              <a-form-model-item label="评分段位" prop="queryParam.achieveStandardItemId">-->
<!--                &lt;!&ndash;       多选组件无法联动，暂未解决联动问题     <j-select-multiple />&ndash;&gt;-->
<!--                <j-dict-select-tag v-model="queryParam.achieveStandardItemId" :dictCode="queryParamSelect.achieveStandardItemIdSelect" />-->
<!--              </a-form-model-item>-->
<!--            </a-col>-->
            <!--              <a-col :span="12">多选下拉框(v-model)：{{ queryParam.examinationPaperId }}</a-col>-->
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label = "分数范围" prop="queryParam.achievementScore">
                <label >[</label>
                <a-input-number label = "分数范围:["  v-model ="queryParam.achievementScore_min" style='width: 60px'></a-input-number>
                <label >-</label>
                <a-input-number label = "-"  v-model ="queryParam.achievementScore_max" style='width: 60px' ></a-input-number>
                <label >)</label>
              </a-form-item>
            </a-col>


            <a-col :xl="4" :lg="7" :md="8" :sm="24">
              <a-form-item label = "班级排名" prop="queryParam.classAchiScoreRank">
                <label >[</label>
                <a-input-number label = "班级排名:["  v-model ="queryParam.classAchiScoreRank_min" style='width: 60px'></a-input-number>
                <label >-</label>
                <a-input-number label = "-"  v-model ="queryParam.classAchiScoreRank_max" style='width: 60px'></a-input-number>
                <label >)</label>
              </a-form-item>

            </a-col>
            <a-col :xl="4" :lg="7" :md="8" :sm="24">
              <a-form-item label = "年级排名" prop="queryParam.gradeAchiScoreRank">
                <label >[</label>
                <a-input-number label = "年级排名:["  v-model ="queryParam.gradeAchiScoreRank_min" style='width: 60px'></a-input-number>
                <label >-</label>
                <a-input-number label = "-"  v-model ="queryParam.gradeAchiScoreRank_max" style='width: 60px'></a-input-number>
                <label >)</label>
              </a-form-item>

            </a-col>


          </a-row>
        </template>
  <a-row >
    <a-col offset='8'>
        <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
    </a-col>
  </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
<!--      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
      <a-button type="primary" icon="download" @click="handleExportXls('v_ach_student_examination_score')">导出</a-button>
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
<!--        <a-button type="primary" icon="import">导入</a-button>-->
<!--      </a-upload>-->
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
<!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
<!--        <a-menu slot="overlay">-->
<!--          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>-->
<!--        </a-menu>-->
<!--        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
<!--      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
<!--          <a @click="handleEdit(record)">编辑</a>-->

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
<!--              <a-menu-item>-->
<!--                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">-->
<!--                  <a>删除</a>-->
<!--                </a-popconfirm>-->
<!--              </a-menu-item>-->
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <ach-student-examination-score-modal ref="modalForm" @ok="modalFormOk"></ach-student-examination-score-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import AchStudentExaminationScoreModal from './modules/AchStudentExaminationScoreModal'
  import { getSubjectList, queryTeacherListBySubject } from '@api/commonAPI'

  export default {
    name: 'AchStudentExaminationScoreList',
    mixins: [JeecgListMixin, mixinDevice],
    components: {
      AchStudentExaminationScoreModal
    },
    data() {
      return {
        description: 'v_ach_student_examination_score管理页面',
        disableMixinCreated: true, //默认不加载数据


        // 查询条件
        queryParam: {
          achiStandPurposeType: "1",
        },
        //查询条件联动部分定义
        queryParamSelect: {
          examinationIdSelect: "ach_examination,examination_name,id,del_flag  =0 and iz_open  =1 order by create_time  desc",
          ttclassIdSelect: "cou_class,class_name,id,class_iz_open  =1 and class_iz_delete  = 0 order by  class_order",
          examinationPaperIdSelect: "ach_examination_paper aep,aep.examination_paper_name,aep.id,aep.iz_open =1 and aep.del_flag =0  order by examination_paper_name",
          achievementStandardIdSelect: null,
          // "ach_achievement_standard aas inner join rel_ach_standard_distribution rasd on aas.id = rasd.achievement_standard_id,aas.achievement_standard_name,aas.id,aas.iz_open =1 and aas.del_flag =0 and rasd.paper_standard_effective =1",
          achieveStandardItemIdSelect: null,
          //"ach_achieve_standard_item,stand_item_name,id,iz_open =1 and del_flag =0 order by exa_pap_pro_item_code",
        },
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender: function(t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '年级',
            align: "center",
            dataIndex: 'gradeName'
          },
          {
            title: '班级',
            align: "center",
            dataIndex: 'className'
          },
          {
            title: '班级简称',
            align: "center",
            dataIndex: 'classNickname'
          },
          {
            title: '学号',
            align: "center",
            dataIndex: 'studentNo'
          },
          {
            title: '学生姓名',
            align: "center",
            dataIndex: 'studentName'
          },
          // {
          //   title: '考试编码',
          //   align: "center",
          //   dataIndex: 'examinationCode'
          // },
          {
            title: '考试',
            align: "center",
            dataIndex: 'examinationName'
          },
          {
            title: '满分',
            align: "center",
            dataIndex: 'examinationFullMarks'
          },
          {
            title: '成绩',
            align: "center",
            dataIndex: 'achievementScore'
          },
          {
            title: '成绩状态',
            align: "center",
            dataIndex: 'achievementStatus_dictText'
          },
          // {
          //   title:'段位名称',
          //   align:"center",
          //   dataIndex: 'standItemName'
          // },
          {
            title: '段位',
            align: "center",
            dataIndex: 'standItemAliasname'
          },
          {
            title: '段位分差',
            align: "center",
            dataIndex: 'diffScore'
          },
          // {
          //   title:'评分标准',
          //   align:"center",
          //   dataIndex: 'achievementStandardName'
          // },
          {
            title: '标准',
            align: "center",
            dataIndex: 'achiStandPurposeType_dictText'
          },
          {
            title: '班级排名',
            align: "center",
            dataIndex: 'classAchiScoreRank'
          },
          {
            title: '年级排名',
            align: "center",
            dataIndex: 'gradeAchiScoreRank'
          },
          {
            title: '考试日期',
            align: "center",
            dataIndex: 'achievementScoreTime',
            customRender: function(text) {
              return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
            }
          }
          // ,
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align:"center",
          //   fixed:"right",
          //   width:147,
          //   scopedSlots: { customRender: 'action' }
          // }
        ],
        url: {
          list: "/achstudent/AchStudentExaminationScoreVo/list",
          // delete: "/achstudent/AchStudentExaminationScoreVo/delete",
          // deleteBatch: "/achstudent/AchStudentExaminationScoreVo/deleteBatch",
          exportXlsUrl: "/achstudent/AchStudentExaminationScoreVo/exportXls",
          importExcelUrl: "achstudent/AchStudentExaminationScoreVo/importExcel",

        },
        dictOptions: {},
        superFieldList: [],
        teacherList: [],
        subjectList: [],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig() {
      },
      //查询条件联动begin //////////////////////////////////////////////////////////////
      //初始化科目信息
      async initsubjectList() {
        let subjectList = await getSubjectList()
        if (subjectList.code === 200) {
          this.subjectList = []
          subjectList.result.forEach(item => {
            this.subjectList.push({
              label: item.subjectName,
              value: item.subjectId
            })
          })
        }
      },
      //科目变更-->更新教师列表
      async handleSubjectChange() {
        let tenantId = ''
        if (localStorage.length > 0) {
          let localData = JSON.parse(localStorage.getItem('pro__Login_Userinfo'))
          tenantId = localData.value.tenantId
          this.queryParam.tenantId = tenantId
        }
        let params = {
          tenantId: tenantId,
          subjectId: this.queryParam.subjectId
        }
        this.getTeacherLists(params)
        // let res = await queryTeacherListBySubject(params)
        // if (res.success) {
        //   this.teacherList = []
        //   res.result.forEach(item => {
        //     this.teacherList.push({
        //       value: item.teacherId,
        //       label: item.teacherName
        //     })
        //   })
        // }

      },
      //初始化教师
      async getTeacherLists(params) {
        var teaparams;
        if (params) { //如果参数存在
          teaparams = params;
        } else { //如果参数不存在
          let tenantId = ''
          if (localStorage.length > 0) {
            let localData = JSON.parse(localStorage.getItem('pro__Login_Userinfo'))
            tenantId = localData.value.tenantId
            this.queryParam.tenantId = tenantId
          }
          teaparams = {
            tenantId: tenantId,
            subjectId: null
          }
        }

        let res = await queryTeacherListBySubject(teaparams)
        if (res.success) {
          this.teacherList = []
          res.result.forEach(item => {
            this.teacherList.push({
              value: item.teacherId,
              label: item.teacherName
            })
          })
        }
      },
      //更改年级-->选择考试，选择班级
      changeGradeId() {
        if (this.queryParam.gradeId) { //判断不为空
          this.queryParamSelect.examinationIdSelect = "ach_examination,examination_name,id,del_flag  =0 and iz_open  =1 and grade_id=\'" + this.queryParam.gradeId + "\' order by create_time  desc";
          this.queryParamSelect.classIdSelect = "cou_class,class_name,id,class_iz_open  =1 and class_iz_delete  = 0 and grade_code=\'" + this.queryParam.gradeId + "\' order by  class_order";
        }
      },
      //更改考试-->选择试卷
      changeExaminationId() {
        if (this.queryParam.examinationId) {
          this.queryParamSelect.examinationPaperIdSelect = "ach_examination_paper aep,aep.examination_paper_name,aep.id,aep.iz_open =1 and aep.del_flag =0 and aep.examination_id =\'" + this.queryParam.examinationId + "\'  order by aep.examination_paper_name";
          // this.queryParamSelect.achievementStandardIdSelect = "ach_achievement_standard,achievement_standard_name,id,iz_open =1 and del_flag =0  order by achievement_standard_order",
          // this.queryParamSelect.examinationIdSelect = "ach_examination,examination_name,id,del_flag  =0 and iz_open  =1 and grade_id='"+ this.queryParam.gradeId +"' order by create_time  desc"
        }
      },
      //更改试卷-->选择标准
      changeExaminationPaperId() {
        if (this.queryParam.examinationPaperId) {
          this.queryParamSelect.achievementStandardIdSelect = "ach_achievement_standard aas inner join rel_ach_standard_distribution rasd on aas.id = rasd.achievement_standard_id,aas.achievement_standard_name,aas.id,aas.iz_open =1 and aas.del_flag =0 and rasd.paper_standard_effective =1 and  rasd.rel_obj_id=\'" + this.queryParam.examinationPaperId + "\'";
        }
      },
      //更改标准-->选择标准分项
      changeAchievementStandardId() {
        if (this.queryParam.achievementStandardId) {
          this.queryParamSelect.achieveStandardItemIdSelect = "ach_achieve_standard_item,stand_item_name,id,iz_open =1 and del_flag =0 and achievement_standard_id = \'" + this.queryParam.achievementStandardId + "\' order by exa_pap_pro_item_code";
        }
      },
      //查询条件联动end //////////////////////////////////////////////////////////////
      getSuperFieldList() {
        let fieldList = [];
        fieldList.push({ type: 'string', value: 'tenantId', text: '学校编码' })
        fieldList.push({ type: 'string', value: 'gradeId', text: 'gradeId' })
        fieldList.push({ type: 'string', value: 'gradeCode', text: '年级编码' })
        fieldList.push({ type: 'string', value: 'gradeName', text: '年级名称' })
        fieldList.push({ type: 'string', value: 'classId', text: '主键ID' })
        fieldList.push({ type: 'string', value: 'classCode', text: '班级编码' })
        fieldList.push({ type: 'string', value: 'className', text: '班级名称' })
        fieldList.push({ type: 'string', value: 'classNickname', text: '班级简称' })
        fieldList.push({ type: 'string', value: 'studentId', text: '主键ID' })
        fieldList.push({ type: 'string', value: 'studentNo', text: '学生学号' })
        fieldList.push({ type: 'string', value: 'studentName', text: '学生姓名' })
        fieldList.push({ type: 'int', value: 'exaPapProItemId', text: 'exaPapProItemId' })
        fieldList.push({ type: 'string', value: 'exaPapProItemCode', text: 'exaPapProItemCode' })
        fieldList.push({ type: 'string', value: 'exaPapProItemName', text: 'exaPapProItemName' })
        fieldList.push({ type: 'string', value: 'subjectId', text: 'subjectId' })
        fieldList.push({ type: 'string', value: 'subjectNames', text: 'subjectNames' })
        fieldList.push({ type: 'string', value: 'teacherId', text: 'teacherId' })
        fieldList.push({ type: 'string', value: 'teacherName', text: 'teacherName' })
        fieldList.push({ type: 'string', value: 'examinationPaperId', text: 'examinationPaperId' })
        fieldList.push({ type: 'string', value: 'examinationPaperNames', text: 'examinationPaperNames' })
        fieldList.push({ type: 'string', value: 'examinationId', text: '所属考试id' })
        fieldList.push({ type: 'string', value: 'examinationCode', text: '考试编码' })
        fieldList.push({ type: 'string', value: 'examinationName', text: '考试名称' })
        fieldList.push({ type: 'int', value: 'gradeOrder', text: '排序' })
        fieldList.push({ type: 'int', value: 'classOrder', text: '班级排序' })
        fieldList.push({ type: 'int', value: 'subjectOrder', text: 'subjectOrder' })
        fieldList.push({ type: 'int', value: 'studentOrder', text: '学生显示顺序' })
        fieldList.push({ type: 'int', value: 'teacherOrder', text: 'teacherOrder' })
        fieldList.push({ type: 'number', value: 'examinationFullMarks', text: 'examinationFullMarks' })
        fieldList.push({ type: 'number', value: 'examinationAchievementScore', text: 'examinationAchievementScore' })
        fieldList.push({ type: 'string', value: 'achievementStatus', text: '成绩状态：1正常(默认) 2缺考 3作弊 4取消' })
        fieldList.push({ type: 'string', value: 'achievementStatusName', text: 'achievementStatusName' })
        fieldList.push({ type: 'date', value: 'achievementScoreTime', text: '考试日期' })
        fieldList.push({ type: 'int', value: 'achievementScoreRank', text: 'achievementScoreRank' })
        fieldList.push({ type: 'string', value: 'achievementStandardId', text: 'achievementStandardId' })
        fieldList.push({ type: 'string', value: 'achievementStandardCode', text: '标准编码' })
        fieldList.push({ type: 'string', value: 'achievementStandardName', text: '标准名称' })
        fieldList.push({ type: 'int', value: 'achievementStandardTtype', text: '标准类型（1国标 2省标 3市区标 4县乡标 5本校标 6自定义标）' })
        fieldList.push({
          type: 'string',
          value: 'achievementStandardPurpose',
          text: '标准用途：11试卷模板 12实际应用于试卷 21个人模板 22应用于个人 31班级模板 32应用于班级 41年级模板 42应用于年级 51学校级模板 52应用于学校 92考试总分标准 93考试总分计分规则'
        })
        fieldList.push({ type: 'int', value: 'achievementStandardOrder', text: '标准序号' })
        fieldList.push({ type: 'string', value: 'achieveStandardItemId', text: 'achieveStandardItemId' })
        fieldList.push({ type: 'string', value: 'standItemCode', text: '标准分项编码' })
        fieldList.push({ type: 'string', value: 'standItemName', text: '标准分项目名称(不及格、及格、良好、优秀等）' })
        fieldList.push({ type: 'string', value: 'standItemAliasname', text: '标准分项目别名简称' })
        fieldList.push({ type: 'number', value: 'standItemLowestScore', text: '分数最低分(含)' })
        fieldList.push({ type: 'number', value: 'standItemHighestScore', text: '分数最高分(不含)' })
        fieldList.push({ type: 'number', value: 'diffScore', text: 'diffScore' })
        fieldList.push({ type: 'int', value: 'scoreSegmentIndex', text: 'scoreSegmentIndex' })
        fieldList.push({ type: 'int', value: 'classAchiScoreRank', text: 'classAchiScoreRank' })
        fieldList.push({ type: 'int', value: 'gradeAchiScoreRank', text: 'gradeAchiScoreRank' })
        this.superFieldList = fieldList
      },
    //校验查询条件：通过ture，不通过false
    checkQueryParam() {
      if (!this.queryParam.gradeId && !this.queryParam.examinationId && !this.queryParam.classId) {
        this.$message.success("请选择年级和考试！");
        return false;
      }
      if (!this.queryParam.gradeId && !this.queryParam.classId) {
        this.$message.success("请选择年级或班级！");
        return false;
      }
      if (!this.queryParam.examinationId && !this.queryParam.classId) {
        this.$message.success("请选择考试！");
        return false;
      }
      return true;
    }
    ,
    searchQuery() {
      //查询条件校验不通过
      if (!this.checkQueryParam()) {
        return;
      }
      this.loadData();
      // 点击查询清空列表选中行
      // https://gitee.com/jeecg/jeecg-boot/issues/I4KTU1
      this.selectedRowKeys = []
      this.selectionRows = []
    },
  }
}
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>